#include<iostream>
#include<stack>
using namespace std;
template<typename T>
struct BTnode {
	BTnode<T>* lchild;
	BTnode<T>* rchild;
	T data;
};

FILE* fp;
template<typename T>
void Pre_order_Creat_from_FILE(BTnode<T>*& root, FILE* fp)
{
	T elem;
	fscanf(fp, "%d", &elem);
	if (elem == 0) {
		root = NULL;
	}
	else {
		root = (BTnode<T>*)malloc(sizeof(BTnode<T>));
		root->data = elem;
		Pre_order_Creat_from_FILE(root->lchild, fp);
		Pre_order_Creat_from_FILE(root->rchild, fp);
	}
}
template<typename T>
void Pre_order_tra(BTnode<T>* root) {
	if (root) {
		cout << root->data << " ";
		Pre_order_tra(root->lchild);
		Pre_order_tra(root->rchild);
	}
}
int main() {
	FILE* fp1;
	fp1 = fopen("test.txt", "r");
	BTnode<int>* root, root1;
	/*Pre_order_Creat_from_CIN(root1);*/
	Pre_order_Creat_from_FILE(root, fp1);
	Pre_order_tra(root);
	return 0;
}